using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_CommonPlayerItem : UIBaseNode
    {
        #region Template Generate,don't modify
        protected class UIB_UIN_CommonPlayerItem
        {
            #region ObjectBinding Generate
            public IQIGame.Onigao.Framework.ExImage playerIMG { protected set; get; }
            public IQIGame.Onigao.Framework.ExText txtLevel { protected set; get; }
            public UnityEngine.Transform playerAvatarFrame { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExImage>("playerIMG", out var __tbv0);
                this.playerIMG = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("txtLevel", out var __tbv1);
                this.txtLevel = __tbv1;
                __binding.TryGetVariableValue<UnityEngine.Transform>("playerAvatarFrame", out var __tbv2);
                this.playerAvatarFrame = __tbv2;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify



        #region fields


        #endregion fields

        #region properties

        protected UIB_UIN_CommonPlayerItem ui { get; set; }
        protected UIMsgDispatcher uiMsgDispatcher => this._msgDispatcher as UIMsgDispatcher;

        #endregion properties

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_CommonPlayerItem();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {


        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }



        /// <summary>
        /// 添加UGUI侦听
        /// </summary>
        protected override void AddUGUIListener()
        {

        }

        /// <summary>
        /// 添加全局侦听（MsgDispatcher）
        /// </summary>
        protected override void AddMsgListeners()
        {

        }

        protected override void OnDispose()
        {

        }



        #region methonds

        public void SetSelf(int avatar, int avatarFrame, int level)
        {
            SetImageSprite(this.ui.playerIMG, TableCenter.playerAvatar.Get(avatar).Url_fullPath);
            var assetName = TableCenter.avatarFrame.Get(avatarFrame).Prefab_fullPath;
            var frame = this.resLoader.LoadABAsset<GameObject>(assetName);
            GameObject.Instantiate(frame, this.ui.playerAvatarFrame);
            this.ui.txtLevel.text = level.ToString();
        }

        #endregion methonds
    }
}